package com.liwang.lanouhn.nvshengo.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.liwang.lanouhn.nvshengo.Info.DressLiveInfo;
import com.liwang.lanouhn.nvshengo.R;
import com.liwang.lanouhn.nvshengo.activities.LiveActivity;
import com.squareup.picasso.Picasso;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by lanouhn on 2016/10/14.
 */
public class DressLiveAdapter extends RecyclerView.Adapter<DressLiveAdapter.DressliveViewHolder> {
    private Context context;
    private List<DressLiveInfo.DataBean.StreamsBean.ItemsBean> itemsBeen;



    public DressLiveAdapter(Context context, List<DressLiveInfo.DataBean.StreamsBean.ItemsBean> itemsBeen) {
        this.context = context;
        this.itemsBeen = itemsBeen;
    }

    @Override
    public DressliveViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_dresslive, null);
        DressliveViewHolder holder = new DressliveViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(DressliveViewHolder holder, final int position) {
        Picasso.with(context).load(itemsBeen.get(position).getSnapshot()).into(holder.iv_background);
        Picasso.with(context).load(itemsBeen.get(position).getUser().getAvatar()).into(holder.iv_head);
        holder.tv_title.setText(itemsBeen.get(position).getChannel().getStatus());
        holder.tv_name.setText(itemsBeen.get(position).getUser().getName());
        holder.tv_view.setText(itemsBeen.get(position).getViewers()+"");
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String id =itemsBeen.get(position).getChannel().getId();
                Intent intent =new Intent(context, LiveActivity.class);
                intent.putExtra("id",id);
                context.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return itemsBeen.size();
    }

    public class DressliveViewHolder extends RecyclerView.ViewHolder {
        private ImageView iv_background;
        private TextView  tv_name, tv_view,tv_title;
        private CircleImageView iv_head;

        public DressliveViewHolder(View itemView) {
            super(itemView);
            iv_background = (ImageView) itemView.findViewById(R.id.iv_back);
            iv_head = (CircleImageView) itemView.findViewById(R.id.iv_head);
            tv_name= (TextView) itemView.findViewById(R.id.tv_name);
            tv_view= (TextView) itemView.findViewById(R.id.tv_view);
            tv_title= (TextView) itemView.findViewById(R.id.tv_title);

        }
    }
}
